﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using PreguntaAlExperto.RulesLayer.Entities;
using PreguntaAlExperto.RulesLayer.Services;
using Microsoft.Security.Application;

namespace PreguntaAlExperto
{
    public partial class Preguntaalexperto : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                AskExpertService _service = new AskExpertService();
                this.DataList1.DataSource = _service.getRootNodes();
                this.DataList1.DataBind();
            }

            if (Session["UserID"] != null)
            {
                this.pnlCommentAction.Visible = true;
                this.pnlMustLoggedToComment.Visible = false;
            }
            else
            {
                this.pnlCommentAction.Visible = false;
                this.pnlMustLoggedToComment.Visible = true;
            }
        }

        protected void AskButton_Click(object sender, EventArgs e)
        {
            string _secTitle = AntiXss.HtmlEncode(this.AskTitle.Text);
            string _secBody = AntiXss.HtmlEncode(this.AskDescription.Text);

            AskNode _node = new AskNode();
            _node.Topic = _secTitle;
            _node.Comment_Body = _secBody;
            _node.Comment_Date = DateTime.Now;
            Publisher _publisher = new Publisher();
            _publisher.ID_Publisher = int.Parse(Session["UserID"].ToString());
            _node.PublisherOwner = _publisher;
            _node.ParentNode = 0;

            AskExpertService _service = new AskExpertService();
            _service.CreateNewNode(_node);

            this.DataList1.DataSource = _service.getRootNodes();
            this.DataList1.DataBind();

            this.AskDescription.Text = "";
            this.AskTitle.Text = "";
        }
    }
}
